//
//  PopoverPresentationController.swift
//  weibo117
//
//  Created by 宋禹奇 on 15/6/29.
//  Copyright © 2015年 宋禹奇. All rights reserved.
//

import UIKit

class PopoverPresentationController: UIPresentationController {
    
    var presentFrame = CGRectZero
    
    //遮罩视图
    lazy var dummyView:UIView = {
    
        let v = UIView()
        
        v.backgroundColor = UIColor(white: 0.0, alpha: 0.2)
        
        return v
  
    }()
    
    
    
    override init(presentedViewController: UIViewController, presentingViewController: UIViewController) {
        super.init(presentedViewController: presentedViewController, presentingViewController: presentingViewController)
        
        prepareDummyView()
        
    }
    

    private func prepareDummyView(){
    
        let tap = UITapGestureRecognizer(target: self, action: "close")
        
        dummyView.addGestureRecognizer(tap)
    
    }
    
    func close(){
    
        presentedViewController.dismissViewControllerAnimated(true, completion: nil)
        
    }
    
    
    override func containerViewWillLayoutSubviews() {
        
        super.containerViewWillLayoutSubviews()
        
        dummyView.frame = containerView!.bounds
        containerView?.insertSubview(dummyView, atIndex: 0)
        
        presentedView()?.frame = presentFrame
        
    }
    
    
}
